package kr.saeildadim.androidexam_saeildamil.chapter8;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Toast;

public class HanndleEvent extends Activity implements View.OnTouchListener{
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		//MyView mv = new MyView(this);
		//setContentView(mv);
		View v =new View(this);
		v.setOnTouchListener(this);
		setContentView(v);
		
	}//oncreat end
	public boolean onTouch(View v, MotionEvent event) {
		if(event.getAction()==MotionEvent.ACTION_DOWN){
			Toast.makeText(HanndleEvent.this, "Point x"+event.getX()+"Point y"+event.getY()+"ACTION_DOWN", Toast.LENGTH_LONG).show();
			return true;
		}else if(event.getAction()==MotionEvent.ACTION_UP){
			Toast.makeText(HanndleEvent.this, "ACTION_UP", Toast.LENGTH_LONG).show();
			return true;
		}
		return false;
	}
	
//	TouchListenerClass listener =new TouchListenerClass();
		
/*	public class TouchListenerClass implements View.OnTouchListener{

		@Override
		public boolean onTouch(View v, MotionEvent event) {
			if(event.getAction()==MotionEvent.ACTION_DOWN){
				Toast.makeText(HanndleEvent.this, "Point x"+event.getX()+"Point y"+event.getY()+"ACTION_DOWN", Toast.LENGTH_LONG).show();
				return true;
			}else if(event.getAction()==MotionEvent.ACTION_UP){
				Toast.makeText(HanndleEvent.this, "ACTION_UP", Toast.LENGTH_LONG).show();
				return true;
			}
			return false;
		}
		
	}*/ 
	
	public class MyView extends View{

		public MyView(Context context) {
			super(context);
		}

		@Override
		public boolean onTouchEvent(MotionEvent event) {
			super.onTouchEvent(event);
			float x = event.getX();
			float y = event.getY();
			if(event.getAction()==MotionEvent.ACTION_DOWN){
				Toast.makeText(HanndleEvent.this, "Point x"+x+"Point y"+y+"ACTION_DOWN", Toast.LENGTH_LONG).show();
				return true;
			}else if(event.getAction()==MotionEvent.ACTION_UP){
				Toast.makeText(HanndleEvent.this, "ACTION_UP", Toast.LENGTH_LONG).show();
				return true;
			}
			return false;
		}//ontouch end
	}

	
	
	
}
